package com.foreknow.tijian.controller;

import com.foreknow.tijian.po.Business;
import com.foreknow.tijian.service.BusinessService;
import com.foreknow.tijian.service.Impl.BusinessServiceImpl;


import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
import java.util.List;

//连接后端和前端
public class BusinessController {
    /**
     * HttpServletRequest
     * 提供一些方法用于获取前台传递到后台的请求参数
     * 客户端向服务端发送请求的url地址
     * http://localhost:8080/elm/BusinessController/listBusinessByOrderTypeId?orderTypeId=1
     * @return
     */
    public Object listBusinessByOrderTypeId(HttpServletRequest request) throws SQLException {
      //获取前台的请求参数
       String orderTypeId= request.getParameter("orderTypeId");
       //调用Service中的方法
       BusinessService businessService=new BusinessServiceImpl();
       List<Business> list=businessService.listBusinessByOrderTypeId(Integer.parseInt(orderTypeId));
       return list;
    }

    /**
     * HttpServletRequest
     * 提供一些方法获取前台传递的请求参数
     * http://localhost:8080/elm/BusinessController/getBusinessById?businessId=10001
     * @param request
     * @return
     * @throws SQLException
     */
    public Object getBusinessById(HttpServletRequest request) throws SQLException {
        String businessId= request.getParameter("businessId");
        //调用service中的方法
        BusinessService businessService=new BusinessServiceImpl();
        Business business=businessService.getBusinessById(Integer.parseInt(businessId));
        return business;

    }
}
